Page({

  /**
   * 页面的初始数据
   */
  data: {
    carSwiper:["../images/swiper_image/swiper04.jpg","../images/swiper_image/swiper02.jpg","../images/swiper_image/swiper03.jpg"],
    carType:[],
    carInfo:[],
    carShow:[],
    bgColor:"#ffffff",
  },
  toCarDetail(e){
    var that = this;
    console.log(e.currentTarget.dataset.index);
    wx.setStorageSync('bind_car_detail_info',that.data.carShow[e.currentTarget.dataset.index]);
    wx.navigateTo({
      url: '../../pages/cardetail/cardetail',
    })
  },
  handleTap(e){
    console.log(e.currentTarget.dataset.index);
    var carShouldPut = [];
    for(var a =0;a<this.data.carInfo.length;a++){
      if(this.data.carInfo[a].categoryName == this.data.carType[e.currentTarget.dataset.index].name){
        carShouldPut.push(this.data.carInfo[a]);
      }
    }
    this.setData({
      carShow:carShouldPut
    })
  },
  handleTap1(e){
    console.log(e.detail.index);
    var that = this;
    var carShouldPut = [];
    var array = this.data.carType;
    for(var k =0;k<this.data.carType.length;k++){
      if(k==e.detail.index){
        array[k].isActive=true;
        this.setData({
          carType:array
        })
      }else{
        array[k].isActive=false;
        this.setData({
          carType:array
        })
      }
    }
    
    for(var a =0;a<this.data.carInfo.length;a++){
      if(this.data.carInfo[a].categoryName == this.data.carType[e.detail.index].name){
        carShouldPut.push(this.data.carInfo[a]);
      }
    }
    this.setData({
      carShow:carShouldPut
    })
  },

  handleTap2(e){
    var that = this;
    var carShouldPut = [];
    var array = this.data.carType;
    for(var k =0;k<this.data.carType.length;k++){
        array[k].isActive=false;
        this.setData({
          carType:array
        })
      }

      for(var a =0;a<this.data.carInfo.length;a++){
          carShouldPut.push(this.data.carInfo[a]);
      }
      this.setData({
        carShow:carShouldPut
      })
    },
  
  /*
  handleTabsItemChange(e){
    console.log(e.detail.index);
  },
  */

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.request({
      url: 'http://localhost:80/category/all',
      success (res) {
          console.log(res);
          console.log(res.data.data)
          var newCarType =[]
          newCarType = res.data.data.map(function(obj) {
            obj.isActive = false; // 添加新的键值对
            return obj;
          })
          that.setData({
            carType: newCarType
          });
          wx.setStorageSync('all_car_info', res.data.data);
          console.log(that.data.carType)
      }
    })

    wx.request({
      url: 'http://localhost:80/car/wx/list',
      success (res) {
          console.log(res);
          console.log(res.data.data)
          wx.setStorageSync('all_car-detail_info', res.data.data)
          that.setData({
            carInfo:res.data.data,
            carShow:res.data.data
          });
      }
    })
  },
  gotoMap(e){
    wx.navigateTo({
      url: '../../pages/map/map',
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },

 
})
